<!doctype html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>商品信息</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <link rel="stylesheet" href="css/index.css">
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->

    <!-- 导入Vue -->
    <script src="js/vue.min.js"></script>
</head>

<body>
    <div id="app" class="container">
        <div class="row">
            <!-- 第一个面板开始-->
            <div class="panel panel-primary">

                <!-- 面板标题 -->
                <div class="panel-heading">
                    <h3 class="panel-title">天狗商场 -- 商品管理</h3>
                </div>

                <!-- 面板内容 -->
                <div class="panel-body">
                    <table class="table">
                        <tr>
                            <th>序号</th>
                            <th>编号</th>
                            <th>名称</th>
                            <th>单价</th>
                            <th>库存</th>
                            <th>小计</th>
                            <th>操作</th>
                        </tr>

                        <tr v-if="productList.length==0">
                            <td colspan="7" align="center">数据为空</td>
                        </tr>

                        <tr v-else v-for="(p,i) in productList" :key="p.id">
                            <td>{{ i +1 }}</td>
                            <td>{{p.id}}</td>
                            <td>{{p.name}}</td>
                            <td>{{p.price}}</td>
                            <td>
                                <button class="btn btn-primary btn-xs" @click="changeCount(i,-1)"
                                    :disabled="p.count<=1?true:false">-</button>
                                <input type="text" v-model="p.count" style="width: 50px;text-align: center;" readonly>
                                <button class="btn btn-primary btn-xs" v-on:click="changeCount(i,+1)">+</button>
                            </td>
                            <td v-color="'blue'">{{ p.price * p.count | format('￥',2) }}</td>
                            <td>
                                <button class="btn btn-danger btn-xs" @click="del(p.id)">删除</button>
                                <button class="btn btn-primary btn-xs" @click="edit(p)">编辑</button>
                            </td>
                        </tr>

                        <tr>
                            <td colspan="7" align="right">
                                总计：<span v-color="'red'">{{ total | format('￥',2) }}</span>
                            </td>
                        </tr>
                    </table>
                </div>

            </div>
            <!-- 第一个面板结束-->



            <!-- 第二个面板开始-->
            <div class="panel panel-warning">

                <!-- 面板标题 -->
                <div class="panel-heading">
                    <h3 class="panel-title">商品详细</h3>
                </div>

                <!-- 面板内容 -->
                <div class="panel-body" style="position: relative;">
                    <form class="form-horizontal" id="frm">

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">编号</label>
                            <div class="col-sm-4">
                                <input type="text" name="pid" ref="pid" class="form-control" id="id" v-model="editProduct.id" :disabled="isUpdate" placeholder="输入编号">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">名称</label>
                            <div class="col-sm-4">
                                <input type="text" name="name" class="form-control" id="name" v-model="editProduct.name" placeholder="输入名称">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">单价</label>
                            <div class="col-sm-4">
                                <input type="text" name="price" class="form-control" id="price" v-model="editProduct.price" placeholder="输入单价">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">库存</label>
                            <div class="col-sm-4">
                                <input type="text" name="count" class="form-control" id="count" v-model="editProduct.count" placeholder="输入库存">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-2 control-label">简介</label>
                            <div class="col-sm-6">
                                <textarea name="desc" class="form-control" rows="3" placeholder="输入简介" v-model="editProduct.desc"></textarea>
                            </div>
                        </div>

                        <input type="hidden" name="image" v-model="editProduct.image"/>
                        
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary" @click.prevent="save">保存</button>
                                <button type="button" class="btn btn-warning" @click="cls">清空</button>
                            </div>
                        </div>
                    </form>

                    <!-- 图片 -->
                    <div id="pic">
                        <img :src="'images/'+ (editProduct.image==undefined?'default.jpeg':editProduct.image)" title="">
                    </div>


                </div>

            </div>
            <!-- 第二个面板结束-->
        </div>
    </div>

    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"
        integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
        crossorigin="anonymous"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>

    <!-- 外部JS -->
    <script src="js/index.js"></script>
</body>

</html>